class EmailController < ApplicationController
  def verify
    email=params[:email]
    code=params[:code]
    email_item=Email.find(:first, :conditions=>["email=? and verify_code=?",email,code])
    if email_item.nil?
      flash[:notice]=info(1,"We don't find the record, please check")
    elsif (Time.now-email_item.verify_sent)>EmailVerifyCodeLife    #life of verification code is 72 hours
      flash[:notice]=info(1,"We are sorry but your code seems to be already expired. The code only lives for 24 hours.")
    elsif email_item.is_verify
      flash[:notice]=info(1,"Your email <b>"+email+"</b> has already been verified for <b>"+email_item.user.fullname+"</b>")
    else
      email_item.is_verify=1
      email_item.verified_at=Time.now
      email_item.save
      flash[:notice]=info(0,"Your email <b>"+email+"</b> has been verified for <b>"+email_item.user.fullname+"</b>. Thank you")
    end
  end
end
